package com.ag.hmk.action;

import javax.annotation.Resource;

import com.ag.bean.TbTeam;
import com.ag.bean.TbType;
import com.ag.common.IDUtil;
import com.ag.common.IIDService;
import com.ag.hmk.service.TbTeamService;
import com.ag.hmk.service.WukuTypeService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author 黄木看
 * 保存救援队伍action
 */
public class SaveTeamAction extends ActionSupport {

	private static final long serialVersionUID = 1544800086718445150L;
	
	private TbTeamService tbTeamServImpl; 
	private WukuTypeService wukuTypeServImpl;
	@Resource(name = "iDServiceImpl")
	private IIDService idservice;
	
	private String teamID1;
	private String teamName1;
	private String teamDuty1;
	private String typeID;
	private String teamContact1;
	private String teamDepart1;
	private String teamLocation1;
	private String teamScale1;
	private String teamTel1;
	
	private String ajaxRST="0";
	
	/*
	 * 新增救援队伍
	 */
	public String saveTeam()throws Exception{
		TbTeam team1 = new TbTeam();
		TbType type1 = wukuTypeServImpl.findTypeByID(typeID);
		if (type1!=null) {
			if (teamName1!=null && teamName1.length()>0 && teamDuty1!=null && teamDuty1.length()>0 &&
				teamDepart1!=null && teamDepart1.length()>0 && teamLocation1!=null && teamLocation1.length()>0 &&
				teamScale1!=null && teamScale1.length()>0 ) {
				
				// String teamID =  (String) idservice.findTablePK(IDUtil.TB_LEVEL);
				//RandomStr tID = new RandomStr();
				//team1.setTeamId(tID.getRandomString(10));
				team1.setTeamId(idservice.findTablePK(IDUtil.TB_TEAM));
				team1.setTeamName(teamName1);
				team1.setTeamDuty(teamDuty1);
				team1.setTbType(type1);
				team1.setTeamContact(teamContact1);
				team1.setTeamDepartment(teamDepart1);
				team1.setTeamLocation(teamLocation1);
				//team1.setTeamScale(Long.valueOf((Long.parseLong(teamScale1))));
				team1.setTeamScale(Integer.valueOf((Integer.parseInt(teamScale1))));
				team1.setTeamTel(teamTel1);
				//team1.setA(IDUtil.PRESERVE);
				

				tbTeamServImpl.saveTeam(team1);
				System.out.println("save team ok!");
				this.ajaxRST="1";
			}else {
				System.out.println("ziduan to be null");
			}
			
		} else {
			
			System.out.println("save team error!");
		}
		return "saveTeamOK";
	}
	
	/*
	 * 更新救援队伍
	 */
	public String updateTeam()throws Exception{
		TbType type1 = wukuTypeServImpl.findTypeByID(typeID);
		if (type1!=null) {
			if (teamName1!=null && teamName1.length()>0 && teamDuty1!=null && teamDuty1.length()>0 &&
				teamDepart1!=null && teamDepart1.length()>0 && teamLocation1!=null && teamLocation1.length()>0 &&
				teamScale1!=null && teamScale1.length()>0 ) {
				
				TbTeam team1 = tbTeamServImpl.findTeamByID(teamID1);
				if (team1!=null) {
					team1.setTeamName(teamName1);
					team1.setTeamDuty(teamDuty1);
					team1.setTbType(type1);
					team1.setTeamContact(teamContact1);
					team1.setTeamDepartment(teamDepart1);
					team1.setTeamLocation(teamLocation1);
					//team1.setTeamScale(Long.valueOf((Long.parseLong(teamScale1))));
					team1.setTeamScale(Integer.valueOf((Integer.parseInt(teamScale1))));
					team1.setTeamTel(teamTel1);
					
					tbTeamServImpl.saveTeam(team1);
					System.out.println("save team ok!");
					this.ajaxRST="1";
					
				} else {
					System.out.println("没找到该记录,无法修改!");
				}
				
			}else {
				System.out.println("非空字段不能为空!");
			}
			
		} else {
			System.out.println("五库类型不能为空!");
		}
		return "updateTeamOK";
	}



	public String getAjaxRST() {
		return ajaxRST;
	}



	public void setAjaxRST(String ajaxRST) {
		this.ajaxRST = ajaxRST;
	}



	public void setTeamName1(String teamName1) {
		this.teamName1 = teamName1;
	}



	public void setTeamDuty1(String teamDuty1) {
		this.teamDuty1 = teamDuty1;
	}



	public void setTypeID(String typeID) {
		this.typeID = typeID;
	}



	public void setTeamContact1(String teamContact1) {
		this.teamContact1 = teamContact1;
	}



	public void setTeamDepart1(String teamDepart1) {
		this.teamDepart1 = teamDepart1;
	}



	public void setTeamLocation1(String teamLocation1) {
		this.teamLocation1 = teamLocation1;
	}



	public void setTeamScale1(String teamScale1) {
		this.teamScale1 = teamScale1;
	}



	public void setTeamTel1(String teamTel1) {
		this.teamTel1 = teamTel1;
	}



	public void setTeamID1(String teamID1) {
		this.teamID1 = teamID1;
	}

	public void setTbTeamServImpl(TbTeamService tbTeamServImpl) {
		this.tbTeamServImpl = tbTeamServImpl;
	}

	public void setWukuTypeServImpl(WukuTypeService wukuTypeServImpl) {
		this.wukuTypeServImpl = wukuTypeServImpl;
	}
}
